<template>
  <view id="app">
    <router-view />
  </view>
</template>

<script>
import store from "@/store";
import { createRouter, createWebHistory } from 'vue-router';
import IndexPage from './pages/index/index.vue';

export default {
  onLaunch: function () {
    console.log('App Launch')
    let is_mobile = navigator.userAgent.indexOf('Mobile')>-1
    store.commit("SET_IS_MOBILE", is_mobile);
    
    // 由于是标准Vue项目，使用localStorage代替uni.getStorageSync
    var token = localStorage.getItem("token");
    if (token && token != "") {
      var userInfo = store.state.userInfo;
      userInfo.isLogin = true;
      store.commit("SET_USER_INFO", userInfo);
    }
    
    // 初始化路由
    this.initRouter();
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
  methods: {
    initRouter() {
      const router = createRouter({
        history: createWebHistory(),
        routes: [
          {
            path: '/',
            name: 'index',
            component: IndexPage
          }
        ]
      });
      
      const app = globalThis.$app;
      if (app) {
        app.use(router);
        // 将路由实例添加到全局，以便组件访问
        globalThis.$router = router;
      }
    }
  }
}
</script>

<style>

@font-face {
    font-family: pangmen;
    src: url('https://oss.hkrin.com/PangMenZhengDaoBiaoTiTi-2.ttf');
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

</style>
